﻿Imports System
Imports System.Workflow.ComponentModel.Compiler

Namespace System.Workflow.ComponentModel
    Friend NotInheritable Class FaultHandlerActivityValidator
        Inherits CompositeActivityValidator
        ' Methods
        Public Overrides Function Validate(ByVal manager As ValidationManager, ByVal obj As Object) As ValidationErrorCollection
            Dim errors As ValidationErrorCollection = MyBase.Validate(manager, obj)
            Dim activity As FaultHandlerActivity = [TryCast](obj,FaultHandlerActivity)
            If (activity Is Nothing) Then
                Throw New ArgumentException(SR.GetString("Error_UnexpectedArgumentType", New Object() { GetType(FaultHandlerActivity).FullName }), "obj")
            End If
            If Not TypeOf activity.Parent Is FaultHandlersActivity Then
                errors.Add(New ValidationError(SR.GetString("Error_FaultHandlerActivityParentNotFaultHandlersActivity"), &H519))
            End If
            If Not TypeOf manager.GetService(GetType(ITypeProvider)) Is ITypeProvider Then
                Throw New InvalidOperationException(SR.GetString("General_MissingService", New Object() { GetType(ITypeProvider).FullName }))
            End If
            Dim item As ValidationError = Nothing
            If (activity.FaultType Is Nothing) Then
                item = New ValidationError(SR.GetString("Error_TypePropertyInvalid", New Object() { "FaultType" }), &H116) { _
                    .PropertyName = "FaultType" _
                }
                errors.Add(item)
            ElseIf Not TypeProvider.IsAssignable(GetType(Exception), activity.FaultType) Then
                item = New ValidationError(SR.GetString("Error_TypeTypeMismatch", New Object() { "FaultType", GetType(Exception).FullName }), &H51A) { _
                    .PropertyName = "FaultType" _
                }
                errors.Add(item)
            End If
            If (activity.EnabledActivities.Count = 0) Then
                errors.Add(New ValidationError(SR.GetString("Warning_EmptyBehaviourActivity", New Object() { GetType(FaultHandlerActivity).FullName, activity.QualifiedName }), &H1A3, True))
            End If
            If (activity.AlternateFlowActivities.Count > 0) Then
                errors.Add(New ValidationError(SR.GetString("Error_ModelingConstructsCanNotContainModelingConstructs"), &H61F))
            End If
            Return errors
        End Function

    End Class
End Namespace

